package com.yy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yy.entity.Vehicle;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VehicleMapper extends BaseMapper<Vehicle> {
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "parking_lot_id",property = "parkingLot",one=@One(select = "com.yy.mapper.ParkingLotMapper.getById")),
    })
    @Select("select * from vehicle join parking_lot " +
            "on parking_lot.id=parking_lot_id ")
    List<Vehicle> getAll();
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "parking_lot_id",property = "parkingLot",one=@One(select = "com.yy.mapper.ParkingLotMapper.getById")),
    })
    @Select("select * from vehicle join parking_lot " +
            "on parking_lot.id=parking_lot_id "+
            "where vehicle.id=#{vehicle.id} ")
    Vehicle getById(Long id);
    @Insert("insert into vehicle set licence_plate=#{licencePlate} "+
            ",picUrl=#{picUrl},is_active=#{isActive} "+
            ",parking_lot_id=#{parkingLot.id} ")
    int insert(Vehicle entity);
    @Update("update vehicle set licence_plate=#{licencePlate} "+
            ",picUrl=#{picUrl},is_active=#{isActive} "+
            ",parking_lot_id=#{parking.id} ")
    int update(Vehicle entity);
}
